package com.qf.lanzhou.blog.api.service.impl.login;

import com.qf.lanzhou.blog.api.dao.Impl.login.UserDaoImpl;
import com.qf.lanzhou.blog.api.dao.UserDao;
import com.qf.lanzhou.blog.api.pojo.entity.User;
import com.qf.lanzhou.blog.api.service.RegisterService;
import com.qf.lanzhou.blog.api.util.MD5Utils;
import sun.security.provider.MD5;

/**
 * @author LEON-HE
 */
public class RegisterServiceImpl implements RegisterService {
    private UserDao userDao = new UserDaoImpl();
    @Override
    public void register(User registerUser) {
        User sUser = userDao.selectUserByUserName(registerUser.getUserName());
        String encode = MD5Utils.stringToMD5(registerUser.getPassword());
        registerUser.setPassword(encode);
        System.out.println(registerUser.getPassword());
        if (sUser!=null){
            System.out.println(sUser);
            throw new RuntimeException("用户名重复，注册失败");
        }
        if (!userDao.selectUserByPhone(registerUser.getPhone())){
            throw new RuntimeException("手机号码已注册，注册失败");
        }
        if (!userDao.saveUser(registerUser)){
            throw new RuntimeException("系统繁忙，注册失败");
        }
        return;
    }
}
